\section{Code for problem 1}
\label{code1}
\small
\begin{verbatim}
# This function generates an estimate of the price of an "up-and-put" option  for a given strike-price.
# Simulated price European put option included for reference.
upandput <- function(N, S_0, r, sigma, K, T, m, H)
{
  mu <- 0
  put <- 0
  
  mu_values <- c()
  put_values <- c()
  
  for(n in 1:N)
  {
    P <- 1
    S <- S_0 

    for(i in 0:(m-1))
    {
      z <- rnorm(1)
      C <- -log(S)
      S <- S * exp((r-0.5 *sigma^2) + sigma*z)
      h <- H(i)
      C <- C + log(h/S)
      p <- 1- exp (-0.5/sigma * C * (z + C/sigma))
      P <- P * p
    }
    
    if (S < K)
    {
      mu <- mu + (K-S)*P
      put_values <- c(put_values,(K-S))
      mu_values <- c(mu_values, (K-S)*P)
    }
    else
    {
      mu_values <- c(mu_values, 0)
      put_values <- c(put_values,0)
    }
  }
  
  mu <- mean(mu_values) * exp(-r*T)
  std_dev <- sqrt(var(mu_values))
  error <- 1.96 * std_dev / sqrt(N)
  res <- c()
  res$mu <- mu
  res$put <- mean(put_values) * exp(-r*T)
  res$error <- error
  
  return (res)
}

N <- 10000
S <- 100
T <- 5
m <- 5
sigma <- 0.3
r <- 0.04
K <- 120
H <- function (x) 105 + 3*x
res <- upandput (N, S, r, sigma, K, T, m, H)
res$mu
res$put
res$error
\end{verbatim}
\newpage